import 'package:shared_preferences/shared_preferences.dart';

class XSave {
  ///获取学习进度
  ///字符串格式的进度，记得转化成int
  getProgress(String id) async {
    var prefs = await SharedPreferences.getInstance();
    String? tmp = prefs.getString(id);
    //字符串格式的进度，记得转化成int
    List<String> tmpArr = tmp!.split("_");
  }

  ///设置学习进度
  setProgress(String id, int index, int similar) async {
    var prefs = await SharedPreferences.getInstance();
    String? tmp = prefs.getString(id);
    List<String> tmpArr = tmp!.split("_");
    tmpArr[index] = "$similar";
    prefs.setString(id, tmpArr.join("_"));
  }

  ///初始化学习进度
  initProcess(String id, int length) async {
    var prefs = await SharedPreferences.getInstance();
    List<String> tmp = new List.generate(length, (index) => "0");
    prefs.setString(id, tmp.join("_"));
  }

  ///判断是否在学习进度中
  Future<bool> isProcess(String id) async {
    print("判断是否在学习进度中");
    var prefs = await SharedPreferences.getInstance();
    return prefs.containsKey(id);
  }
}
